package conu.mapmaker.display;

import java.awt.Color;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

import conu.mapmaker.area.City;
import conu.mapmaker.area.Sector;

/**
 * @author Tiny
 * 
 */
public class Content extends JPanel implements MouseListener, DisplayInterface {

	private City city;

	public Content() {
		this.setLayout(null);
		this.addMouseListener(this);
		this.setSize(FRAME_DIM, FRAME_DIM);
		this.setBackground(Color.BLACK);

		// insert sector number 400*width, 300*height
		city = new City(4, 3);
		display();
	}

	/**
	 * Initializes Content panel
	 */

	/**
	 * Method that draws all the objects within Content
	 * 
	 * @param g
	 *            Graphics variable that does all the drawing
	 */

	public void display() {
		this.add(city);

		city.setBounds(city.getXOffset(), city.getYOffset(), (int) (city.getPreferredSize().getWidth()), (int) (city.getPreferredSize().getHeight()));
	}

	public boolean intoCity(int x, int y) {
		return ((x >= city.getXOffset()) && (x < (FRAME_DIM - city.getXOffset())) && (y >= city.getYOffset()) && (y < (FRAME_DIM - city.getYOffset())));
	}

	@Override
	public void mouseClicked(MouseEvent e) {
            switch(e.getClickCount()){
                case 1: oneClickProcedure(e); 
                    break;
                case 2: twoClickProcedure(e);
                    break;
                default:System.out.println("well... aren't you a hungry hungry hippo");
                    break;
            }
        }
        
        public void oneClickProcedure(MouseEvent e){
            if (intoCity(e.getX(), e.getY())) {
                city.detectSector(e.getX() - city.getXOffset(), e.getY() - city.getYOffset());
                //this should display element properties
                System.out.println("Click on element");
            } else {
                //this should display container properties
                //this should de-select all elements
                System.out.println("Click on container");
            }
        }
        
        public void twoClickProcedure(MouseEvent e){
            if (intoCity(e.getX(), e.getY())) {
                city.detectSector(e.getX() - city.getXOffset(), e.getY() - city.getYOffset());
                //this should be zoom in
                System.out.println("Double click on element");
            } else {
                //this should be zoom out
                System.out.println("Double click on container");
            }
        }

	@Override
	public void mouseEntered(MouseEvent arg0) {}

	@Override
	public void mouseExited(MouseEvent arg0) {}

	@Override
	public void mousePressed(MouseEvent e) {}
            
        @Override
	public void mouseReleased(MouseEvent arg0) {}

}